package com.swanclouds.redfish.common.redfish;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.swanclouds.model.common.redfish.CollectionResource;

import java.util.ArrayList;
import java.util.List;

/**
 * 集合资源信息
 *
 * @author 张立强 
 */
public class CollectionResourceModel implements CollectionResource {

    @JsonProperty("Members@odata.count")
    private Integer memberCount;
    /**
     * 系统资源数量
     *
     * @return memberCount
     */
    @Override
    public Integer getMemberCount() {
        return this.memberCount;
    }

    @JsonProperty("Members")
    private List<MemberModel> members;
    /**
     * 系统集合成员列表
     *
     * @return java.util.List
     */
    @Override
    public List<String> getCollectionResourceList() {
        List<String> collectionResourceList = new ArrayList<>();
        if (this.members != null && this.members.size() > 0) {
            this.members.stream().forEach(member -> {
                collectionResourceList.add(member.getDataId());
            });
        }
        return collectionResourceList;
    }

    @JsonProperty("@odata.id")
    private String dataId;
    /**
     * 返回解析 @odata.id
     * @return String
     */
    @Override
    public String getDataId() {
        return this.dataId;
    }

    @JsonProperty("Name")
    private String name;
    /**
     * Name
     *
     * @return String
     */
    @Override
    public String getName() {
        return this.name;
    }

    @JsonProperty("@odata.context")
    private String context;
    /**
     * 返回解析 @odata.context
     * @return String
     */
    @Override
    public String getContext() {
        return this.context;
    }

    @JsonProperty("@odata.type")
    private String type;
    /**
     * 返回解析 @odata.type
     * @return String
     */
    @Override
    public String getType() {
        return type;
    }

    @Override
    public String toString() {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.writeValueAsString(this);
        } catch (JsonProcessingException e) {
        }
        return "CollectionResourceModel {" +
                "memberCount=" + memberCount +
                ", members=" + members +
                ", dataId='" + dataId + '\'' +
                ", name='" + name + '\'' +
                ", context='" + context + '\'' +
                ", type='" + type + '\'' +
                '}';
    }
}
